/*     */ package com.cr.web.controller.system;
/*     */ 
/*     */ import com.cr.common.config.RuoYiConfig;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.domain.entity.SysMenu;
/*     */ import com.cr.common.core.domain.entity.SysUser;
/*     */ import com.cr.common.core.text.Convert;
/*     */ import com.cr.common.utils.CookieUtils;
/*     */ import com.cr.common.utils.MyDateUtils;
/*     */ import com.cr.common.utils.MyStringUtils;
import com.cr.common.utils.ServletUtils;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import com.cr.framework.shiro.service.SysPasswordService;
/*     */ import com.cr.system.service.ISysConfigService;
/*     */ import com.cr.system.service.ISysMenuService;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.Cookie;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ public class SysIndexController extends BaseController {
/*     */   @Autowired
/*     */   private ISysMenuService menuService;
/*     */   
/*     */   @Autowired
/*     */   private ISysConfigService configService;
/*     */   
/*     */   @Autowired
/*     */   private SysPasswordService passwordService;
/*     */   
/*     */   @GetMapping({"/index"})
/*     */   public String index(ModelMap mmap) {
/*  51 */     SysUser user = getSysUser();
/*  53 */     List<SysMenu> menus = this.menuService.selectMenusByUser(user);
/*  54 */     mmap.put("menus", menus);
/*  55 */     mmap.put("user", user);
/*  56 */     mmap.put("sideTheme", this.configService.selectConfigByKey("sys.index.sideTheme"));
/*  57 */     mmap.put("skinName", this.configService.selectConfigByKey("sys.index.skinName"));
/*  58 */     mmap.put("ignoreFooter", this.configService.selectConfigByKey("sys.index.ignoreFooter"));
/*  59 */     mmap.put("copyrightYear", RuoYiConfig.getCopyrightYear());
/*  60 */     mmap.put("demoEnabled", Boolean.valueOf(RuoYiConfig.isDemoEnabled()));
/*  61 */     mmap.put("isDefaultModifyPwd", Boolean.valueOf(initPasswordIsModify(user.getPwdUpdateDate())));
/*  62 */     mmap.put("isPasswordExpired", Boolean.valueOf(passwordIsExpiration(user.getPwdUpdateDate())));
/*  63 */     mmap.put("isMobile", Boolean.valueOf(ServletUtils.checkAgentIsMobile(ServletUtils.getRequest().getHeader("User-Agent"))));
/*  66 */     String menuStyle = this.configService.selectConfigByKey("sys.index.menuStyle");
/*  68 */     String indexStyle = ServletUtils.checkAgentIsMobile(ServletUtils.getRequest().getHeader("User-Agent")) ? "index" : menuStyle;
/*  71 */     Cookie[] cookies = ServletUtils.getRequest().getCookies();
/*  72 */     for (Cookie cookie : cookies) {
/*  74 */       if (StringUtils.isNotEmpty(cookie.getName()) && "nav-style".equalsIgnoreCase(cookie.getName())) {
/*  76 */         indexStyle = cookie.getValue();
/*     */         break;
/*     */       } 
/*     */     } 
/*  80 */     String webIndex = "topnav".equalsIgnoreCase(indexStyle) ? "index-topnav" : "index";
/*  81 */     return webIndex;
/*     */   }
/*     */   
/*     */   @GetMapping({"/lockscreen"})
/*     */   public String lockscreen(ModelMap mmap) {
/*  88 */     mmap.put("user", getSysUser());
/*  89 */     ServletUtils.getSession().setAttribute("lockscreen", Boolean.valueOf(true));
/*  90 */     return "lock";
/*     */   }
/*     */   
/*     */   @PostMapping({"/unlockscreen"})
/*     */   @ResponseBody
/*     */   public AjaxResult unlockscreen(String password) {
/*  98 */     SysUser user = getSysUser();
/*  99 */     if (MyStringUtils.isNull(user))
/* 101 */       return AjaxResult.error("服务器超时，请重新登陆"); 
/* 103 */     if (this.passwordService.matches(user, password)) {
/* 105 */       ServletUtils.getSession().removeAttribute("lockscreen");
/* 106 */       return AjaxResult.success();
/*     */     } 
/* 108 */     return AjaxResult.error("密码不正确，请重新输入。");
/*     */   }
/*     */   
/*     */   @GetMapping({"/system/switchSkin"})
/*     */   public String switchSkin() {
/* 115 */     return "skin";
/*     */   }
/*     */   
/*     */   @GetMapping({"/system/menuStyle/{style}"})
/*     */   public void menuStyle(@PathVariable String style, HttpServletResponse response) {
/* 122 */     CookieUtils.setCookie(response, "nav-style", style);
/*     */   }
/*     */   
/*     */   @GetMapping({"/system/main"})
/*     */   public String main(ModelMap mmap) {
/* 129 */     mmap.put("version", RuoYiConfig.getVersion());
/* 130 */     return "main";
/*     */   }
/*     */   
/*     */   public boolean initPasswordIsModify(Date pwdUpdateDate) {
/* 136 */     Integer initPasswordModify = Convert.toInt(this.configService.selectConfigByKey("sys.account.initPasswordModify"));
/* 137 */     return (initPasswordModify != null && initPasswordModify.intValue() == 1 && pwdUpdateDate == null);
/*     */   }
/*     */   
/*     */   public boolean passwordIsExpiration(Date pwdUpdateDate) {
/* 143 */     Integer passwordValidateDays = Convert.toInt(this.configService.selectConfigByKey("sys.account.passwordValidateDays"));
/* 144 */     if (passwordValidateDays != null && passwordValidateDays.intValue() > 0) {
/* 146 */       if (MyStringUtils.isNull(pwdUpdateDate))
/* 149 */         return true; 
/* 151 */       Date nowDate = MyDateUtils.getNowDate();
/* 152 */       return (MyDateUtils.differentDaysByMillisecond(nowDate, pwdUpdateDate) > passwordValidateDays.intValue());
/*     */     } 
/* 154 */     return false;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysIndexController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */